package com.longdaji.decoration.ui.news;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.longdaji.decoration.R;
import com.longdaji.decoration.data.bean.NewsType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by longtao on 2018/1/31.
 */

public class InfoTypeAdapter extends RecyclerView.Adapter<InfoTypeAdapter.ViewHolder> {
    private List<NewsType> mNewsTypeList;

    public InfoTypeAdapter(List<NewsType> newsTypeList) {
        if (newsTypeList == null)
            newsTypeList = new ArrayList<>();
        this.mNewsTypeList = newsTypeList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_news_type, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        NewsType newsType = mNewsTypeList.get(position);
        holder.newsTypeName.setText(newsType.getNewsTypeName());
        holder.newsTypePic.setBackgroundResource(newsType.getNewTypeImg());
    }

    @Override
    public int getItemCount() {
        return mNewsTypeList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView newsTypePic;
        TextView newsTypeName;

        public ViewHolder(View itemView) {
            super(itemView);
            newsTypeName = (TextView) itemView.findViewById(R.id.tv_news_type_name);
            newsTypePic = (ImageView) itemView.findViewById(R.id.iv_news_type_img);
        }
    }

}
